package leecode

import "strings"

func reverseWords(s string) string {
	wrod := strings.Split(s, " ")
	result := make([]string, 0, len(s))
	for _, value := range wrod {
		result = append(result, reverseString(value))
	}
	return strings.Join(result, " ")
}

// 反转字符串
func reverseString(s string) string {
	//将字符串转化为整型切片
	runes := []rune(s)
	left := 0
	right := len(runes) - 1
	for left <= right {
		runes[left], runes[right] = runes[right], runes[left]
		left++
		right--
	}
	return string(runes)
}
